package com.apps.goods.script;

import com.apps.goods.event.sGoodsEvent;
import com.apps.goods.model.po.KupaGoods;
import com.apps.goods.service.IKupaGoodsService;
import com.apps.sannotation.service.SuportService;
import com.apps.thirdparty.solr.service.IKupaSolrService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品对象跟solr同步数据的脚本
 */
@SuportService(service = IKupaGoodsService.class)
@Component
public class IKupaGoodsScript implements sGoodsEvent<KupaGoods>
{

    @Autowired
    private IKupaSolrService solrService;

    @SneakyThrows
    @Override
    public void onCreated(KupaGoods goods) {
        solrService.saveToSolr(goods);
    }

    @SneakyThrows
    @Override
    public void onUpdated(KupaGoods goods) {
       solrService.updateById(goods);
    }

    @SneakyThrows
    @Override
    public void onDeleted(List<KupaGoods> goods) {
       for(KupaGoods item:goods)
          solrService.removeById(item);
    }
}
